import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'

import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    AutoImport({
      resolvers: [ElementPlusResolver()],
    }),
    Components({
      resolvers: [ElementPlusResolver()],
    }),
  ],
  base:'/add-money/',
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  },
   // 配置前端服务地址和端口
  server: {
    // 启动时自动在浏览器中打开应用程序
    open: true,
    // 支持局域网浏览
    host: '0.0.0.0',
    // 端口号
    port: 8001,
    // 若端口号被占用是否直接退出
    strictPort: false,
    // 是否启用 https
    https: false,
    proxy: {
        '/add-money': {
            target: 'http://sherlingh.gitee.io/add-money',
            changeOrigin: true,
            ws: true,
            rewrite: url => url.replace(/^\/add-money/, ''),
        },
    },
  },
})
